<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>子数组的最小值之和</title>
</head>
<body>
  <script>
    function fn(arr) {
      let len = arr.length
      let mod = 10 ** 9 + 7
      let ans = 0
      for (let i = 0; i < len; i++) {
        let tempCount = 0
        let min = arr[i]
        for (let j = i; j < len; j++) {
          if (arr[j] <= min) {
            min = arr[j]
          }
          tempCount += min
        }
        ans += tempCount
      }
      return ans % mod
    }
    console.log(fn([3, 1, 2, 4]))
  </script>
</body>
</html>